Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: INITIALIZE_DEFAULT / FINALIZE_DEFAULT => initialize! / finalize! #597

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

simonbyrne
Copy link
Contributor

@simonbyrne simonbyrne commented Oct 21, 2020

Not sure what you think about this, but we want to be able to define callbacks that have predefined initializer/finalizers, e.g.

struct Diagnostics
  # some stuff
end
DiffEqBase.initialize!(d::Diagnostics, u, t, integrator) = # set up stuff
DiffEqBase.finalize!(d::Diagnostics, u, t, integrator) = # finalize stuff

DiscreteCallback(mycond, Diagnostics(details)) # don't need to pass explicit initializer / finalizer functions

We could do this now by defining additional methods for INITIALIZE_DEFAULT / FINALIZE_DEFAULT, but this seems a bit clearer.

If you're on board, I can add some docs.

We want to be able to define callbacks that have predefined initializer/finalizers, e.g.
```
struct Diagnostics
  # some stuff
end
DiffEqBase.initialize!(d::Diagnostics, u, t, integrator) = # set up stuff
DiffEqBase.finalize!(d::Diagnostics, u, t, integrator) = # finalize stuff

DiscreteCallback(mycond, Diagnostics(details)) # don't need to pass explicit initializer / finalizer functions
```

We could do this now by defining additional methods for `INITIALIZE_DEFAULT` / `FINALIZE_DEFAULT`, but this seems a bit clearer.

If you're on board, I can add some docs.
@simonbyrne simonbyrne changed the title INITIALIZE_DEFAULT / FINALIZE_DEFAULT => initialize! / finalize! RFC: INITIALIZE_DEFAULT / FINALIZE_DEFAULT => initialize! / finalize! Oct 21, 2020
@simonbyrne
Copy link
Contributor Author

Okay, I realise this won't quite work as it is passed the DiscreteCallback, not the affect! argument.

I'll need to think a bit more about this.

@simonbyrne
Copy link
Contributor Author

@ChrisRackauckas
Copy link
Member

Yeah I see what you're getting at. Usually for this kind of thing I'd make a callable type will all of the function dispatches and pass that type in all spots, but the init and finalize functions would clash so that's a little tricky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants